package logic

import (
	"context"
	"ture/models/mysql"

	"ture/turerpc/internal/svc"
	"ture/turerpc/turerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *turerpc.UserListRequest) (*turerpc.UserListResponse, error) {
	// todo: add your logic here and delete this line

	var user []mysql.User
	mysql.DB.Debug().Find(&user)
	var userList []*turerpc.UserList
	for _, m := range user {
		list := turerpc.UserList{
			Id:       int64(m.ID),
			Name:     m.Name,
			Image:    m.Image,
			Account:  m.Account,
			Password: m.Password,
		}
		userList = append(userList, &list)
	}
	return &turerpc.UserListResponse{
		List: userList,
	}, nil
}
